home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 7684 / 7684.xpi / resources / fmPrivate.js < prev    next >
Text File  |  2009-11-20  |  4KB  |  120 lines

  1. /**
  2.  * Copyright (c) 2009, Jose Enrique Bolanos, Jorge Villalobos
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions are met:
  7.  *
  8.  *  * Redistributions of source code must retain the above copyright notice,
  9.  *    this list of conditions and the following disclaimer.
  10.  *  * Redistributions in binary form must reproduce the above copyright notice,
  11.  *    this list of conditions and the following disclaimer in the documentation
  12.  *    and/or other materials provided with the distribution.
  13.  *  * Neither the name of Jose Enrique Bolanos, Jorge Villalobos nor the names
  14.  *    of its contributors may be used to endorse or promote products derived
  15.  *    from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  21.  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25.  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26.  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  **/
  29.  
  30. var EXPORTED_SYMBOLS = [];
  31.  
  32. const Cc = Components.classes;
  33. const Ci = Components.interfaces;
  34. const Ce = Components.Exception;
  35.  
  36. Components.utils.import("resource://firefm/fmCommon.js");
  37. Components.utils.import("resource://firefm/fmHistory.js");
  38.  
  39. const TOPIC_PRIVATE_BROWSING = "private-browsing";
  40.  
  41. /**
  42.  * FireFM Private Mode handler.
  43.  */
  44. FireFM.Private = {
  45.  
  46.   /* Logger for this object. */
  47.   _logger : null,
  48.   /* Private browsing service. */
  49.   _privateService : null,
  50.   /* Flag that indicates the current private mode state. */
  51.   _isPrivateMode : false,
  52.   /* Private mode preference object. */
  53.   _privateModePref : null,
  54.  
  55.   /**
  56.    * Initializes the object.
  57.    */
  58.   init : function() {
  59.     this._logger = FireFM.getLogger("FireFM.Private");
  60.     this._logger.debug("init");
  61.  
  62.     try {
  63.       this._privateService =
  64.         Cc["@mozilla.org/privatebrowsing;1"].
  65.           getService(Ci.nsIPrivateBrowsingService);
  66.       this._isPrivateMode = this._privateService.privateBrowsingEnabled;
  67.  
  68.       FireFM.obsService.addObserver(this, TOPIC_PRIVATE_BROWSING, false);
  69.     } catch (e) {
  70.       this._logger.info("init. Private browsing not supported.");
  71.     }
  72.  
  73.     // get the preference value.
  74.     this._privateModePref =
  75.       FireFM.Application.prefs.get(FireFM.PREF_BRANCH + "enablePrivateMode");
  76.   },
  77.  
  78.   /**
  79.    * Indicates if the browser is in private mode AND the preference is set to
  80.    * enable private mode.
  81.    * @return true if private mode needs to be enforced, false otherwise.
  82.    */
  83.   get isPrivate() {
  84.     this._logger.trace("[getter] isPrivate");
  85.  
  86.     return (this._isPrivateMode && this._privateModePref.value);
  87.   },
  88.  
  89.   /**
  90.    * Observes topic notifications.
  91.    * @param aSubject The object that experienced the change.
  92.    * @param aTopic The topic being observed.
  93.    * @param aData The data relating to the change.
  94.    */
  95.   observe : function(aSubject, aTopic, aData) {
  96.     this._logger.debug("observe");
  97.  
  98.     if (TOPIC_PRIVATE_BROWSING == aTopic) {
  99.       FireFM.Station.stop();
  100.       this._isPrivateMode = ("enter" == aData);
  101.  
  102.       if (!this._isPrivateMode && this._privateModePref.value) {
  103.         let lastStation = FireFM.History.stationHistory[0];
  104.  
  105.         // reset the last played station.
  106.         if (lastStation) {
  107.           FireFM.Station.setStation(lastStation.id, lastStation.type);
  108.         }
  109.       }
  110.     }
  111.   }
  112. };
  113.  
  114. /**
  115.  * FireFM.Private constructor.
  116.  */
  117. (function() {
  118.   this.init();
  119. }).apply(FireFM.Private);
  120.